package com.hspedu.newData.dmsxl.哈希表;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-28 
 * @Version: 1.0
 */

public class LC12整数转罗马数字 {

    public String intToRoman(int num) {
        int[] vals = new int[]{1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < vals.length; i++) {
            int val = vals[i];

            while(num >= val){
                num -= val;
                sb.append(symbols[i]);
            }
            if (num == 0){
                break;
            }
        }
        return sb.toString();
    }
}
